﻿using System;
using System.Collections.Generic;
using System.Web;

using Net.DataAccess;

namespace Net.BusinessLogic
{
	public class Type : BizObject
	{
		private string _id = "";
		public string ID { get { return _id; } }

		private DateTime _addedDate = DateTime.Now;
		public DateTime AddedDate { get { return _addedDate; } }

		private string _addedBy = "";
		public string AddedBy { get { return _addedBy; } }

		private string _name = "";
		public string Name { get { return _name; } set { _name = value; } }

		private string _description = "";
		public string Description { get { return _description; } set { _description = value; } }

		public Type(string id, DateTime addedDate, string addedBy, string name, string description)
		{
			_id = id;
			_addedDate = addedDate;
			_addedBy = addedBy;
			_name = name;
			_description = description;
		}

		public static Type FindByID(string id)
		{
			Type obj = null;
			string key = "categorytype_"+ id.ToString();
			if (Settings.EnableCaching && Cache[key] != null)
				obj = (Type)Cache[key];
			else
			{
				obj = Get(Provider.CategoryType.FindByID(id));
				CacheData(key, obj);
			}
			return obj;
		}

		/*******************
		 * PRIVATE METHODS *
		 *******************/
		private static Type Get(TypeDetails r)
		{
			if (r == null) return null;
			return new Type(r.ID, r.AddedDate, r.AddedBy, r.Name, r.Description);
		}
		private static List<Type> GetList(List<TypeDetails> rs)
		{
			List<Type> items = new List<Type>();
			foreach (TypeDetails r in rs)
				items.Add(Get(r));
			return items;
		}
	}
}